import pandas as pd

df = pd.DataFrame([[i * 2 for i in range(0, 10)], [i + 1 for i in range(0, 10)]])
print(df)

def _d(x):
    # 必须是数字？
    return 1

print(df.sort_index(ascending=False).rolling(window=2).apply(_d, raw=True).sort_index(ascending=True))
